package cn.com.ghy.android.widget.chat;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import cn.com.ghy.android.bean.CustomerInfoBean;
import cn.com.ghy.android.bean.DataCollectDayInfoBean;
import cn.com.ghy.android.widget.R;

/**
 * @软件著作权:金红叶纸业集团有限公司
 * @系统名称:SFA系统
 * @Description:上架SKU显示
 * @author wuz  @date 2011-6-23 14:10:57
 * @版本历史:v1.0
 * @Copyright:Copyright (c) 2011-2012 
 */

public class LastBismt extends Activity {

	private TextView labTxtCustomerId = null;
	private TextView labTxtCustomerName = null;
	private TextView labTxtBismtNum = null;
	private ListView listLastBismtLay = null;
	private ImageButton btnBack = null;

	private CustomerInfoBean customerInfo = null;
	private List<DataCollectDayInfoBean> dataCollectDayInfoList = null;
	private Bundle bundle = null;
	private LastBismtAdatper lastBismtAdatper = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.last_bismt);
		getSession();
		setToolBar();
		findView();
		init();
		addListener();
	}

	@SuppressWarnings("unchecked")
	private void getSession() {
		bundle = getIntent().getExtras();
		customerInfo = (CustomerInfoBean) bundle.getSerializable("customerInfo");
		dataCollectDayInfoList = (List<DataCollectDayInfoBean>) bundle
				.getSerializable("dataCollectDayInfoList");
	}

	private void setToolBar() {
		View appToolBar = findViewById(R.id.appToolBar);
		ImageButton btnList = (ImageButton) appToolBar.findViewById(R.id.btnList);
		btnList.setVisibility(View.GONE);
		btnBack = (ImageButton) appToolBar.findViewById(R.id.btnBack);
	}

	private void findView() {
		labTxtCustomerId = (TextView) findViewById(R.id.labTxtCustomerId);
		labTxtCustomerName = (TextView) findViewById(R.id.labTxtCustomerName);
		labTxtBismtNum = (TextView) findViewById(R.id.labTxtBismtNum);
		listLastBismtLay = (ListView) findViewById(R.id.listLastBismtLay);
	}

	private void init() {
		labTxtCustomerId.setText(customerInfo.getPartner());
		labTxtCustomerName.setText(customerInfo.getName_org1());
		labTxtBismtNum.setText(dataCollectDayInfoList.size() + "");
		lastBismtAdatper = new LastBismtAdatper(LastBismt.this, dataCollectDayInfoList);
		listLastBismtLay.setAdapter(lastBismtAdatper);
	}

	private void addListener() {
		btnBack.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				LastBismt.this.finish();

			}
		});
	}

	private class LastBismtAdatper extends BaseAdapter {

		private Context context = null;
		private List<DataCollectDayInfoBean> list = null;

		public LastBismtAdatper(Context context, List<DataCollectDayInfoBean> list) {
			this.context = context;
			this.list = list;
		}

		public int getCount() {
			return list.size();
		}

		public DataCollectDayInfoBean getItem(int position) {
			return list.get(position);
		}

		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(inflater);
			LinearLayout linearLayout = (LinearLayout) layoutInflater.inflate(
					R.layout.last_bismt_lay, null);
			DataCollectDayInfoBean bean = list.get(position);
			TextView tv = (TextView) linearLayout.findViewById(R.id.labBismt);
			tv.setText((position + 1) + ".SKU:");
			tv = (TextView) linearLayout.findViewById(R.id.labTxtBismt);
			tv.setText(bean.getBismt());
			tv = (TextView) linearLayout.findViewById(R.id.labTxtSide);
			tv.setText(bean.getSide());
			tv = (TextView) linearLayout.findViewById(R.id.labTxtPrice);
			tv.setText(bean.getSaleprice());
			tv = (TextView) linearLayout.findViewById(R.id.labTxtUnit);
			tv.setText(bean.getUnitInfo().getUnitname());
			return linearLayout;
		}

	}

}
